/**
 * Created by Administrator on 2017/11/24.
 */
//var url = 'http://edu.yzztnet.com/public/api/index.php/jiajiao/interface/';
var Sid ='';
//轮播图开始
$.ajax({
    url: url + 'lunbo',
    data: {},
    type: 'post',
    dataType: 'json',
    async: 'true',
    timeout: 2000,
    success: function (data) {
        var lunbo = data.data;
        var code = data.code;
        var status = data.status;
        if (code == '1000' && status == '1') {
            var htmls = "";
            for (var i = 0; i < lunbo.length; i++) {
                htmls += '<div class="swiper-slide"><img src="' + lunbo[i] + '" class="auto_img"></div>';
            }
            $('.index_carousel>.swiper-wrapper').html(htmls);
        }
    },
    error: function () {
        var htmls = '<div class="swiper-slide"><img src="images/default.jpg" class="auto_img"></div>';
        $('.index_carousel>.swiper-wrapper').html(htmls);
    }
});
//轮播图结束

//获取剧种开始
$.ajax({
    url: url + 'getjuzhong?type=1',
    data: {},
    type: 'post',
    dataType: 'json',
    async: 'true',
    timeout: 2000,
    success: function (data) {
        if (data.code = '1000' && data.status == '1') {
            var html = '';
            $.each(data.data, function (k, v) {
                html += '<div class="swiper-slide item">'
                    + '<a href="list.html?juzhong=' + this.name + '" title="' + this.name + '">'
                    + '<div class="icon">'
                    + '<img src="images/icon_home_lishi@2x.png">'
                    + '</div>'
                    + '<div class="txt">' + this.name + '</div>'
                    + '</a>'
                    + '</div>';
            });
            $('#juZhong').html(html);
        }
    },
    error: function (data) {

    }
});
//获取剧种结束

//行当开始
$.ajax({
    url: url + 'gethangdang',
    type: 'post',
    data: {},
    dataType: 'json',
    async: 'true',
    timeout: 2000,
    success: function (data) {
        if (data.code == '1000' && data.status == '1') {
            var hangDang = data.data;
            var html = '';
            var alertH = '';
            var arr =[];
            $.each(hangDang, function (k, v) {
                html += '<div class="swiper-slide item">'
                    + '<a href="javascript:void(0);" title="' + this.type + '" data-am-modal="{target:' + " '#alertH" + k + "'" + '}">'
                    + '<div class="icon">'
                    + '<img src="images/icon_home_lishi@2x.png">'
                    + '</div>'
                    + '<div class="txt">' + this.type + '</div>'
                    + '</a>'
                    + '</div>';
                alertH += '<div class="am-modal am-modal-alert" tabindex="-1" id="alertH'+k+'">'
                    + ' <div class="am-modal-dialog">'
                    + ' <div class="am-modal-hd classTitle">'+this.type+'</div>'

                    + '<div class="subClass">'

                    + '</div>'
                    + '</div>'
                    + '</div>';
                var dT = this.type;
                var subHtml='';
                $.each(this.value, function (kk, vv) {

                    subHtml +=' <a href="list.html?hangdang='+vv+'">'
                        +'<div class="am-modal-bd sub-window">'
                        +vv
                        +'</div>'
                        +'</a>';
                    //console.log(dT + '子标题:' + vv);

                })
                var subHtmls=subHtml;
                subHtml ='';
                arr.push(subHtmls);

            })
            $('#hangDang').html(html);
            $('#hdAlert').html(alertH);
            $.each(arr,function (k,v) {
                $('#alertH'+k+'>.am-modal-dialog>.subClass').html(this);
            })


        }
    },
    error: function (data) {
        console.log(数据加载失败);
    }
});

//行当结束

//首页老师列表开始
$.ajax({
    url:url+'getteachers?page=10',
    type:'post',
    data:{},
    dataType:'json',
    async:'true',
    timeout:2000,
    success:function (data) {
        if(data.code=='1000'&&data.status=='1'){
            var indexLt =data.data;
            var html ='';
            $.each(indexLt,function (k,v) {
                this.xingbie==1?this.xingbie='女':this.xingbie='男';
                this.isrenzheng==0? this.isrenzheng='认证':this.isrenzheng='未认证';
                html +='<div class="teacher_l">'
                    + '<a href="teDetails.html?id='+this.id+'&name='+this.xingming+'">'
                    +  '<div class="header_h">'
                    +  '<div class="price-wrap_h">'
                    +  '<div class="prices">'
                    + ' ¥'+this.price
                    +  '<span>起</span>'
                    +  '</div>'
                    + '</div>'
                    + '<div class="teacher_imgs">'
                    +  '<img src="'+this.headimage+'" alt="">'
                    + '</div>'
                    +  '<div class="info">'
                    + '<p class="rel">'
                    +  '<span class="txt">'+this.xingming+'</span>'
                    +  '</p>'
                    + '<div class="sub-txt">'
                    + '<b>性别:</b>'+this.xingbie
                    +  '</div>'
                    + '<div class="sub-txt">'
                    + '<b>行当:</b>'+this.hangdang
                    +  '</div>'
                    + '<div class="tags">'
                    +  '<span><em></em>'+this.isrenzheng+'</span>'
                    +  '</div>'
                    +  '<a class="am-btn am-btn-warning am-btn-xs am-round am-fr zixun" onclick="getId(this)" id="'+this.id+'"  data-am-modal="{target:'+"'#my-alert'"+'}" data-id="'+this.id+'">立即预约</a>'

                    +  '</div>'
                    + '</div>'
                    +  '</a>'
                    +  '</div>';
            });
            $('.teacher_all').html(html);
            //console.log(html);
        }
    },
    error:function () {
        console.log('数据加载失败');
    }
});
function getId(data) {
    sid = $(data).attr('id');
    sessionStorage.setItem('id',sid);
}
